<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Pithy{

	private $view = null;
	
	public function __construct(){
		
		$this->view = new View();
		$this->run();
	}
	
	private function run(){
		
		
		$r = new Router();
		
		$d = $r->getDirectory();
		$c = $r->getClass();
		$m = $r->getMethod();

		if($d){
			include_once RUN_PATH . 'action/' . $d . '/' . $c . '.php';	
		}else{
			include_once RUN_PATH . 'action/' . $c . '.php';
		}
		
		if(class_exists($c)){
			$class = new $c();
			
			if(method_exists($class, $m)){
				
				//Keep Step 1
				$this->view->setHook($r->getArgs());
				
				//Keep Step 2
				$return = call_user_func_array(array($class, $m), $r->getArgs());
	
				
				$this->display($return);
//				if(is_int($return)){
//				
//				}else if(isset($return)){
//					
//				}
			}else{
				show_404();
			}
		}else{
			show_404();		
		}
		
	}
	
	private function display($return){
		$this->view->display('page', $return);
	}
}